<%--
  Created by IntelliJ IDEA.
  User: Lt
  Date: 2018/5/17
  Time: 22:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>

<title>促销管理 - 卡卷</title>

<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jquery-ui/jquery-ui.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jqgrid/ui.jqgrid.css"/>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${contextPath}/static/statistics/js/vue.js"></script>
<script src=${contextPath}/static/layer/layui.all.js></script>
<script src="${contextPath}/static/countjs/regularYz.js"></script>


<style type="text/css">
    .customBtn {
        line-height: 20px;
        margin-bottom: 3px;
    }

    .btnLine {
        margin-left: 1px;
        margin-top: 8px;
        margin-bottom: 2px;
    }

    @-webkit-keyframes bouncedelay {
        0%, 80%, 100% {
            -webkit-transform: scale(0.0)
        }
        40% {
            -webkit-transform: scale(1.0)
        }
    }

    @keyframes bouncedelay {
        0%, 80%, 100% {
            transform: scale(0.0);
            -webkit-transform: scale(0.0);
        }
        40% {
            transform: scale(1.0);
            -webkit-transform: scale(1.0);
        }
    }

    .autocomplete-suggestions {
        border: 1px solid #999;
        background: #FFF;
        overflow: auto;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestions strong {
        font-weight: normal;
        color: #3399FF;
    }

    @-moz-document url-prefix() {
        fieldset {
            display: table-cell;
        }
    }

    .ui-jqgrid .ui-priority-secondary{
        background: #d5effc;
    }

    .ui-jqgrid .ui-jqgrid-title{font-size:12px;}    /*修改grid标题的字体大小*/

    .ui-jqgrid-sortable {font-size:12px;}   /*修改列名的字体大小*/

    .ui-jqgrid tr.jqgrow td {font-size:12px; font-family:"宋体"} /*修改表格内容字体*/

    /*****  表头样式  ******/
    /*.ui-jqgrid .ui-jqgrid-titlebar{*/
        /*background-color: #878787;*/
        /*height: 36px;*/
    /*}*/
    /*****  标题样式  ******/
    .ui-jqgrid-sortable {
        text-align: center;
    }


</style>

<div class="row" id="appAlert">
    <div class="row btnLine">
        <div class="button-len col-sm-12">
            <div style="width: 100%; margin-bottom: 10px;">
                <button class="btn btn-white btn-sm btn-purple customBtn"  id="addCoupon">
                    <i class="ace-icon fa fa-plus-circle purple"></i> 新增
                </button>
                <button class="btn btn-white btn-info btn-sm customBtn" id="editCoupon">
                    <i class="ace-icon fa fa-pencil blue"></i> 修改
                </button>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="deleteSupplier">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 删除--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="editState">--%>
                    <%--<i class="ace-icon fa fa-key red"></i> 修改状态--%>
                <%--</button>--%>
                <%--<label style="">状态</label>--%>
                <%--<select class="input-sm" id="state1">--%>
                <%--<option selected="selected" value="1">新建</option>--%>
                <%--<option value="2">正常</option>--%>
                <%--<option value="3">业务冻结</option>--%>
                <%--<option value="4">财务冻结</option>--%>
                <%--<option value="4">停用</option>--%>
                <%--</select>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 复制--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 打印--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 导出--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 设置--%>
                <%--</button>--%>
                <%--<button class="btn btn-white btn-info btn-sm customBtn" id="">--%>
                <%--<i class="ace-icon fa fa-key red"></i> 退出--%>
                <%--</button>--%>
            </div>
            <input class="input-sm" type="text" id="keyword" style="margin-left: 0px;" value=""
                   placeholder="关键字">
            <button class="btn btn-sm btn-white btn-info search-len customBtn"
                    onclick="searchShop()">
                <i class="ace-icon fa fa-search orange"></i>搜索
            </button>
        </div>
    </div>
    <!-- 内容数据开始 -->
    <div class="col-xs-12" style="text-align: center;">
        <table class="center" id="grid-coupon-table"></table>

        <div id="grid-coupon-pager"></div>

    </div>

    <!-- 内容数据结束 -->

    <!-- 新增模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="">
            <div class="modal-content">
                <div class="modal-header" style="font-size: 20px; margin-bottom: -15px;">
                    <h4 class="modal-title" id="myModalLabel">
                        卡卷 - <span id="alertTitle">新增</span>
                        <small id="smallTitle" class="hide" style="color: red; float: right; margin-top: 10px;"></small>

                    </h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <input type="text" class="input-sm hide" style="margin-left: 2px;" id="id" placeholder="id">
                        <div class="button-len col-sm-12" style="margin-top: 5px; margin-bottom: 5px;">
                            <label for="" style="margin-left: 25px">券包编号：</label>
                            <input type="text" class="input-sm" style="margin-left: 2px;" id="cardNo" placeholder="券包编号">
                        </div>
                        <div class="button-len col-sm-12" style="margin-top: 5px; margin-bottom: 5px;">
                            <label for="" style="margin-left: 25px">券包名称：</label>
                            <input type="text" class="input-sm" style="margin-left: 2px;" id="cardName" placeholder="券包名称">
                        </div>
                        <div class="button-len col-sm-12" style="margin-top: 5px; margin-bottom: 5px;">
                            <label for="" style="margin-left: 25px">销售价格：</label>
                            <input type="text" class="input-sm" style="margin-left: 2px;" id="cardPrice" placeholder="销售价格">
                        </div>
                        <div class="button-len col-sm-12" style="margin-top: 5px; margin-bottom: 5px;">
                            <label for="" style="margin-left: 53.1px">状态：</label>
                            <select class="input-sm" id="state"  style="margin-left: 2px; width: 156px;" >
                                <option value="1">有效</option>
                                <option value="0">无效</option>
                            </select>
                        </div>
                        <div class="button-len col-sm-12" style="margin-top: 5px; margin-bottom: 5px;">
                            <label for="" style="margin-left: 53.1px">描述：</label>
                            <input type="text" class="input-sm" style="margin-left: 2px;" id="remark" placeholder="描述">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default btn-xs" data-dismiss="modal" v-on:click="close">关闭</button>
                    <button type="button" class="btn btn-primary btn-xs" v-on:click="saveCoupon">提交更改</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>

    <!--  模态框（Modal） -->
    <!-- 品牌 -->
    <div id="container">
        <div id="example1" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <a class="close" data-dismiss="modal">×</a>
                        <h3>修改状态</h3>
                    </div>
                    <div class="modal-body">
                        <label style="">状态</label>
                        <select class="input-sm" id="state1">
                            <option selected="selected" value="1">新建</option>
                            <option value="2">正常</option>
                            <option value="3">业务冻结</option>
                            <option value="4">财务冻结</option>
                            <option value="4">停用</option>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default btn-xs" data-dismiss="modal" v-on:click="close">关闭</button>
                        <button type="button" class="btn btn-primary btn-xs" id="saveState">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input type="text" name="fileStr" id="fileStr" style="display:none"/>
<input type="text" name="fileType" id="fileType" style="display:none"/>

<!-- page specific plugin scripts -->
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.mockjax.js"></script>
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
<!-- 公用变量 -->
<script type="text/javascript">

    var grid_coupon_selector = "#grid-coupon-table";
    var pager_coupon_selector = "#grid-coupon-pager";

    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

    var img64 = "";

    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

    var queryModel = {
        //分页参数
        page: '1',
        rows: '10',
    }

    $("#id").show();
    $("#showImageInfoImg").attr("src", img64);
    $("#showImageInfoImg1").attr("src", img64);

</script>

<!-- Vue实现 -->
<script type="text/javascript">
    var app = new Vue({
        el: '#appAlert',
        data: {
            objects: [],
        },
        methods: {
            saveCoupon: function () {
                queryObjects()
            },
        }
    });
</script>

<!-- 方法调用 -->
<script type="text/javascript">


    $('#beginTime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd",
//        startDate:new Date(),
    });


    $('#endTime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd",
//        startDate:new Date(),
    });

</script>

<!-- jqGrid 公用方法 -->
<script type="application/javascript">

    function style_edit_form(form) {
        //enable datepicker on "sdate" field and switches for "stock" field
        //form.find('input[name=sdate]').datepicker({format:'yyyy-mm-dd' , autoclose:true})

        //form.find('input[name=stock]').addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
        //don't wrap inside a label element, the checkbox value won't be submitted (POST'ed)
        //.addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');


        //update buttons classes
        var buttons = form.next().find('.EditButton .fm-button');
        buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide();//ui-icon, s-icon
        buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
        buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>')

        buttons = form.next().find('.navButton a');
        buttons.find('.ui-icon').hide();
        buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
        buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');
    }

    function style_delete_form(form) {
        var buttons = form.next().find('.EditButton .fm-button');
        buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide();//ui-icon, s-icon
        buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
        buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
    }

    function style_search_filters(form) {
        form.find('.delete-rule').val('X');
        form.find('.add-rule').addClass('btn btn-xs btn-primary');
        form.find('.add-group').addClass('btn btn-xs btn-success');
        form.find('.delete-group').addClass('btn btn-xs btn-danger');
    }

    function style_search_form(form) {
        var dialog = form.closest('.ui-jqdialog');
        var buttons = dialog.find('.EditTable')
        buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
        buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
        buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
    }

    function beforeDeleteCallback(e) {
        var form = $(e[0]);
        if (form.data('styled')) return false;

        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        style_delete_form(form);
        form.data('styled', true);
    }

    function beforeEditCallback(e) {
        var form = $(e[0]);
        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        style_edit_form(form);
    }


    //it causes some flicker when reloading or navigating grid
    //it may be possible to have some custom formatter to do this as the grid is being created to prevent this
    //or go back to default browser checkbox styles for the grid
    function styleCheckbox(table) {
        /**
         $(table).find('input:checkbox').addClass('ace')
         .wrap('<label />')
         .after('<span class="lbl align-top" />')


         $('.ui-jqgrid-labels th[id*="_cb"]:first-child')
         .find('input.cbox[type=checkbox]').addClass('ace')
         .wrap('<label />').after('<span class="lbl align-top" />');
         */
    }


    //unlike navButtons icons, action icons in rows seem to be hard-coded
    //you can change them like this in here if you want
    function updateActionIcons(table) {
        /**
         var replacement =
         {
             'ui-ace-icon fa fa-pencil' : 'ace-icon fa fa-pencil blue',
             'ui-ace-icon fa fa-trash-o' : 'ace-icon fa fa-trash-o red',
             'ui-icon-disk' : 'ace-icon fa fa-check green',
             'ui-icon-cancel' : 'ace-icon fa fa-times red'
         };
         $(table).find('.ui-pg-div span.ui-icon').each(function(){
				var icon = $(this);
				var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
				if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
			})
         */
    }

    //replace icons with FontAwesome icons like above
    function updatePagerIcons(table) {
        var replacement =
            {
                'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
                'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
                'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
                'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
            };
        $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
            var icon = $(this);
            var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

            if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
        })
    }

    function enableTooltips(table) {
        $('.navtable .ui-pg-button').tooltip({container: 'body'});
        $(table).find('.ui-pg-div').tooltip({container: 'body'});
    }

    //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

    $(document).one('ajaxloadstart.page', function (e) {
        $.jgrid.gridDestroy(grid_selector);
        $('.ui-jqdialog').remove();
    });

</script>

<!-- jqGrid加载数据 -->
<script type="text/javascript">
    var scripts = [null, "${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js", "${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js", "${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js", "${contextPath}/static/layer/layer.js","${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js", "${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js", null]
    $('.page-content-area').ace_ajax('loadScripts', scripts, function () {
        jQuery(function ($) {
            jQuery(grid_coupon_selector).jqGrid({
                subGrid: false,
                <%--url: "${contextPath}/",--%>
                //data: grid_data,
//                datatype: "json",
                datatype : "local",
                mtype: 'POST',
                height: 350,
                colNames : [ '行号', '编号', '描述', '券类型', '发放状态','操作日期'],
                colModel : [
                    {name : 'id',index : 'id',sorttype : "int"},
                    {name : 'invdate',index : 'invdate',sorttype : "date"},
                    {name : 'name',index : 'name'},
                    {name : 'amount',index : 'amount',align : "right",sorttype : "float"},
                    {name : 'tax',index : 'tax',align : "right",sorttype : "float"},
                    {name : 'total',index : 'total',align : "right",sorttype : "float"},
                ],
                rownumbers: true, //自动行数
                autowidth:true,  //宽度自适应
                viewrecords: true,
                rowNum : 10,//一页显示多少条
                rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
                pager : pager_coupon_selector,//表格页脚的占位符(一般是div)的id
                sortname : 'gmtModifiedStr',//初始化的时候排序的字段
                sortorder : "desc",//排序方式,可选desc,asc
                altRows: true,
                multiselect: true,
                multiboxonly: false,

                loadComplete: function () {
                    var table = this;
                    setTimeout(function () {
                        styleCheckbox(table);
                        updateActionIcons(table);
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                },

                editurl: "${contextPath}/ktSaleProject/saveSaleProject",//nothing is saved
                caption: "卡卷列表",
                jsonReader: {
                    root: "recordList",
                    page: "currentPage",
                    total: "pageCount",
                    records: "recordCount"
                }
//                editurl : ctx+"/RowEditing",
//                caption : "Using events example"
            });

            jQuery(grid_coupon_selector).jqGrid('navGrid', '#addpager', {
                edit : false,
                add : false,
                del : false,
                search : false
            });

            $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size

            var mydata = [
                {id : "1",invdate : "2007-10-01",name : "test",note : "note",amount : "200.00",tax : "10.00",total : "210.00"},
                {id : "2",invdate : "2007-10-02",name : "test2",note : "note2",amount : "300.00",tax : "20.00",total : "320.00"},
                {id : "3",invdate : "2007-09-01",name : "test3",note : "note3",amount : "400.00",tax : "30.00",total : "430.00"},
                {id : "4",invdate : "2007-10-04",name : "test",note : "note",amount : "200.00",tax : "10.00",total : "210.00"},
                {id : "5",invdate : "2007-10-05",name : "test2",note : "note2",amount : "300.00",tax : "20.00",total : "320.00"},
                {id : "6",invdate : "2007-09-06",name : "test3",note : "note3",amount : "400.00",tax : "30.00",total : "430.00"},
                {id : "7",invdate : "2007-10-04",name : "test",note : "note",amount : "200.00",tax : "10.00",total : "210.00"},
                {id : "8",invdate : "2007-10-03",name : "test2",note : "note2",amount : "300.00",tax : "20.00",total : "320.00"},
                {id : "9",invdate : "2007-09-01",name : "test3",note : "note3",amount : "400.00",tax : "30.00",total : "430.00"}
            ];
            for ( var i = 0; i <= mydata.length; i++){
                $(grid_coupon_selector).jqGrid('addRowData', i + 1, mydata[i]);
            }
        });
    });

</script>

<!-- 模态框 -->
<script>
    jQuery(function($){
        //解决模态框背景色越来越深的问题
        $(document).on('show.bs.modal', '.modal', function(event) {
            $(this).appendTo($('body'));
        }).on('shown.bs.modal', '.modal.in', function(event) {
            setModalsAndBackdropsOrder();
        }).on('hidden.bs.modal', '.modal', function(event) {
            setModalsAndBackdropsOrder();
        });

        function setModalsAndBackdropsOrder() {
            var modalZIndex = 1040;
            $('.modal.in').each(function(index) {
                var $modal = $(this);
                modalZIndex++;
                $modal.css('zIndex', modalZIndex);
                $modal.next('.modal-backdrop.in').addClass('hidden').css('zIndex', modalZIndex - 1);
            });
            $('.modal.in:visible:last').focus().next('.modal-backdrop.in').removeClass('hidden');
        }

        //覆盖Modal.prototype的hideModal方法
        $.fn.modal.Constructor.prototype.hideModal = function () {
            var that = this
            this.$element.hide()
            this.backdrop(function () {
                //判断当前页面所有的模态框都已经隐藏了之后body移除.modal-open，即body出现滚动条。
                $('.modal.fade.in').length === 0 && that.$body.removeClass('modal-open')
                that.resetAdjustments()
                that.resetScrollbar()
                that.$element.trigger('hidden.bs.modal')
            })
        }
    });
</script>

<!-- 模态框 -->
<script type="text/javascript">
    $("#editState").click(function () {
        var id = $(grid_coupon_selector).jqGrid('getGridParam', 'selrow');
        if (!id) {
            layer.msg("提示：请选择一条信息");
            return;
        }
        var rowData = $(grid_coupon_selector).jqGrid('getRowData', id);
        $('#example1').modal('show');
    });

    $("#saveState").click(function () {
        var id = $(grid_coupon_selector).jqGrid('getGridParam', 'selrow');
        var rowData = $(grid_coupon_selector).jqGrid('getRowData', id);
        var data = [];
        data.id = id;
        data.state = $("#state1").val();
        console.log(data)
        getObjects(data)
        $('#example1').modal('hide');
    })
</script>
